package com.bkgy.modular.rollwlcc.controller;

import com.alibaba.fastjson.JSON;
import com.bkgy.modular.rollwlcc.entity.JRollWlcc;
import com.bkgy.modular.rollwlcc.entity.RollWlcc;
import com.bkgy.modular.rollwlcc.service.RollWlccService;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 新全生命周期控制器层
 *
 * @author 生成器生成
 * @date 2021-01-11 10:56:05
 */
@RestController
@RequestMapping("/rollWlcc")
public class RollWlccController {

    @Autowired
    private RollWlccService rollWlccService;

    /**
     * 添加记录
     */
    @CrossOrigin
    @RequestMapping(value = {"/insert"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData insertDataRollWlcc(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return rollWlccService.insertDataRollWlcc(data, userId, CodiUtil.returnLm(sname));
    }

    /**
     * 根据主键删除对象
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteOne"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataRollWlccOne(@RequestBody String data) {
        try {
            JRollWlcc jrollWlcc = JSON.parseObject(data, JRollWlcc.class);
            return rollWlccService.deleteDataRollWlccOne(jrollWlcc.getIndocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键字符串删除多个对象
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/deleteMany"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData deleteDataSysUserMany(@RequestBody String data) {
        try {
            JRollWlcc jrollWlcc = JSON.parseObject(data, JRollWlcc.class);
            return rollWlccService.deleteDataRollWlccMany(jrollWlcc.getStr_indocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 修改记录
     *
     * @param data       json字符串
     * @param loginToken 请求头参数字符串对象
     */
    @CrossOrigin
    @RequestMapping(value = {"/update"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData updateDataRollWlcc(@RequestBody String data, @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return rollWlccService.updateDataRollWlcc(data, userId, CodiUtil.returnLm(sname));
    }

    /**
     * 分页查看记录
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByPage"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataRollWlccByPage(@RequestBody String data) {
        return rollWlccService.findDataRollWlccByPage(data);
    }

    /**
     * 根据主键查询单条记录
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findByIndocno"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findDataRollWlccByIndocno(@RequestBody String data) {
        return rollWlccService.findDataRollWlccByIndocno(data);
    }

    /**
     * 查看记录
     *
     * @return list 对象集合返回
     */
    @CrossOrigin
    @RequestMapping(value = {"/findAll"}, method = RequestMethod.POST)
    public List<RollWlcc> findDataRollWlcc() {
        return rollWlccService.findDataRollWlcc();
    }

    /**
     * 事故辊管理页面专用——根据封锁时间和辊号，查询磨削量不为0的正序三次下机时间不重复数据，重复的依旧显示
     */
    @CrossOrigin
    @RequestMapping(value = {"/findWlccA"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findWlccA(@RequestBody String data) {
        return rollWlccService.findWlccA(data);
    }

    /**
     * 3-6磨床,查询磨削支数、磨削总量(包括正常辊和事故辊)，
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findchartsnosum"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findchartsnosum(@RequestBody String data) {
        return rollWlccService.findchartsnosum(data);
    }

    /**
     * 3-6磨床,查询磨削支数、磨削总量(包括正常辊和事故辊)，
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findchartsdo"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findchartsdo(@RequestBody String data) {
        return rollWlccService.findchartsdo(data);
    }


    /**
     * 1-2磨床,查询磨削支数、磨削总量(包括正常辊和事故辊)，
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findchartsnosum_b"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findchartsnosum_b(@RequestBody String data) {
        return rollWlccService.findchartsnosum_b(data);
    }


    /**
     * 3-6磨床,查询磨削支数、磨削总量(包括正常辊和事故辊)，
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findchartsdo_b"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findchartsdo_b(@RequestBody String data) {
        return rollWlccService.findchartsdo_b(data);
    }


    /**
     * 3-6磨床,查询磨削支数、磨削总量(包括正常辊和事故辊)，
     *
     * @param data json字符串
     */
    @CrossOrigin
    @RequestMapping(value = {"/findmotable"}, method = RequestMethod.POST)
    @ResponseBody
    public ResultData findmotable(@RequestBody String data) {
        return rollWlccService.findmotable(data);
    }
}
